{extend name="base" /}
{block name="body"}

<div class="admin-main">
<div class="layui-field-box layui-form">
				<a href="{:url('admin/menu/add')}" class="layui-btn layui-btn-sm" id="add">
					<i class="layui-icon">&#xe608;</i> 添加后台菜单
				</a>
				<table class="layui-table admin-table ">
                    <thead>
                    <tr>
                        <th style="width: 30px;">ID</th>
                        <th style="width: 30px;">排序</th>
                        <th>菜单名称</th>
                        <th>控制器方法</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach name="admin_menu_level_list" item="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td>{$vo.sort}</td>
                        <td>{if condition="$vo['level'] gt 1"}|{php}for($i=1;$i<$vo['level'];$i++){echo ' --';}{/php}{/if} {$vo.title}</td>
                        <td>{$vo.name}</td>
                        <td ><input type="checkbox" name="status" lay-skin="switch" lay-text="显示|隐藏" lay-filter="switchTest"  value="{$vo['id']}" {php}echo $vo['status']==1 ? 'checked' : '';{/php}></td>
                        <td>
                            <a href="{:url('admin/menu/add',['pid'=>$vo['id']])}" class="layui-btn layui-btn-sm">添加子菜单</a>
                            <a href="{:url('admin/menu/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-sm">编辑</a>
                            <a href="javascript:;"  data-id="{$vo.id}" data-url="{:url('admin/menu/delete',array('id'=>$vo['id']))}" data-opt="del"  class="elementdel layui-btn layui-btn-danger layui-btn-sm ajax-delete">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>

{/block}
    {block name="js"}
<script type="text/javascript" src="__ADMIN__/js/delelement.js"></script>
 {/block}
    {block name="script"}
    <script>
layui.use(['form'],function(){
  var form = layui.form
  ,jq = layui.jquery;
 var status=0;
 form.on('switch(switchTest)', function(data){
	  loading = layer.load(2, {
	      shade: [0.2,'#000']
	    });
	    if(data.elem.checked){
	    	status=1;
	    }else{
	    	status=0;
	    }
	    var url="{:url('admin/menu/updatestatus')}?id="+data.value+'&status='+status ;
	    jq.get(url,function(data){
	    	
	      if(data.code == 200){
	        layer.close(loading);
	        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
	        //  location.reload();
	        });
	      }else{
	        layer.close(loading);
	        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
	      }
	    });
	    return false;
	  });

})
</script>
 {/block}